using System;
using System.Configuration;
using System.Data;
using digit.Core;

namespace SMS.ServiceManager
{
    public class TeamManager
    {
        #region CONSTRUCTORS
        static TeamManager()
        {
            _data = new TeamData(Util.GetConnectionString("SMSSERVICE"));
            _error = "";
        }
        #endregion

        #region ATTRIBUTES
        private static TeamData _data;
        private static string _error;
        #endregion

        #region PROPERTIES
        public static string ErrorMessage
        {
            get
            {
                return _error;
            }
        }

        #endregion

        #region METHODS
        public static bool Insert(string teamName, string teamNameShort, string foundedDate, string shirtColor, string website, string stadium, string coach, string logoPath, string uniformPath, string info, string createdBy, DateTime createdDate, byte type, byte status)
        {
            _error = "";
            try
            {
                object[] values = new object[14];
                values[0] = Util.ReplaceNullTo(teamName, DBNull.Value);
                values[1] = Util.ReplaceNullTo(teamNameShort, DBNull.Value);
                values[2] = Util.ReplaceNullTo(foundedDate, DBNull.Value);
                values[3] = Util.ReplaceNullTo(shirtColor, DBNull.Value);
                values[4] = Util.ReplaceNullTo(website, DBNull.Value);
                values[5] = Util.ReplaceNullTo(stadium, DBNull.Value);
                values[6] = Util.ReplaceNullTo(coach, DBNull.Value);
                values[7] = Util.ReplaceNullTo(logoPath, DBNull.Value);
                values[8] = Util.ReplaceNullTo(uniformPath, DBNull.Value);
                values[9] = Util.ReplaceNullTo(info, DBNull.Value);
                values[10] = Util.ReplaceNullTo(createdBy, DBNull.Value);
                values[11] = Util.ReplaceNullTo(createdDate, DBNull.Value);
                values[12] = Util.ReplaceNullTo(type, DBNull.Value);
                values[13] = Util.ReplaceNullTo(status, DBNull.Value);

                return _data.Insert(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Insert(TeamInfo info)
        {
            _error = "";
            try
            {
                object[] values = new object[14];
                values[0] = Util.ReplaceNullTo(info.TeamName, DBNull.Value);
                values[1] = Util.ReplaceNullTo(info.TeamNameShort, DBNull.Value);
                values[2] = Util.ReplaceNullTo(info.FoundedDate, DBNull.Value);
                values[3] = Util.ReplaceNullTo(info.ShirtColor, DBNull.Value);
                values[4] = Util.ReplaceNullTo(info.Website, DBNull.Value);
                values[5] = Util.ReplaceNullTo(info.Stadium, DBNull.Value);
                values[6] = Util.ReplaceNullTo(info.Coach, DBNull.Value);
                values[7] = Util.ReplaceNullTo(info.LogoPath, DBNull.Value);
                values[8] = Util.ReplaceNullTo(info.UniformPath, DBNull.Value);
                values[9] = Util.ReplaceNullTo(info.Info, DBNull.Value);
                values[10] = Util.ReplaceNullTo(info.CreatedBy, DBNull.Value);
                values[11] = Util.ReplaceNullTo(info.CreatedDate, DBNull.Value);
                values[12] = Util.ReplaceNullTo(info.Type, DBNull.Value);
                values[13] = Util.ReplaceNullTo(info.Status, DBNull.Value);

                return _data.Insert(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Update(long teamID, string teamName, string teamNameShort, string foundedDate, string shirtColor, string website, string stadium, string coach, string logoPath, string uniformPath, string info, string createdBy, DateTime createdDate, byte type, byte status)
        {
            _error = "";
            try
            {
                object[] values = new object[15];
                values[0] = teamID;
                values[1] = Util.ReplaceNullTo(teamName, DBNull.Value);
                values[2] = Util.ReplaceNullTo(teamNameShort, DBNull.Value);
                values[3] = Util.ReplaceNullTo(foundedDate, DBNull.Value);
                values[4] = Util.ReplaceNullTo(shirtColor, DBNull.Value);
                values[5] = Util.ReplaceNullTo(website, DBNull.Value);
                values[6] = Util.ReplaceNullTo(stadium, DBNull.Value);
                values[7] = Util.ReplaceNullTo(coach, DBNull.Value);
                values[8] = Util.ReplaceNullTo(logoPath, DBNull.Value);
                values[9] = Util.ReplaceNullTo(uniformPath, DBNull.Value);
                values[10] = Util.ReplaceNullTo(info, DBNull.Value);
                values[11] = Util.ReplaceNullTo(createdBy, DBNull.Value);
                values[12] = Util.ReplaceNullTo(createdDate, DBNull.Value);
                values[13] = Util.ReplaceNullTo(type, DBNull.Value);
                values[14] = Util.ReplaceNullTo(status, DBNull.Value);

                return _data.Update(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Update(TeamInfo info)
        {
            _error = "";
            try
            {
                object[] values = new object[15];
                values[0] = info.TeamID;
                values[1] = Util.ReplaceNullTo(info.TeamName, DBNull.Value);
                values[2] = Util.ReplaceNullTo(info.TeamNameShort, DBNull.Value);
                values[3] = Util.ReplaceNullTo(info.FoundedDate, DBNull.Value);
                values[4] = Util.ReplaceNullTo(info.ShirtColor, DBNull.Value);
                values[5] = Util.ReplaceNullTo(info.Website, DBNull.Value);
                values[6] = Util.ReplaceNullTo(info.Stadium, DBNull.Value);
                values[7] = Util.ReplaceNullTo(info.Coach, DBNull.Value);
                values[8] = Util.ReplaceNullTo(info.LogoPath, DBNull.Value);
                values[9] = Util.ReplaceNullTo(info.UniformPath, DBNull.Value);
                values[10] = Util.ReplaceNullTo(info.Info, DBNull.Value);
                values[11] = Util.ReplaceNullTo(info.CreatedBy, DBNull.Value);
                values[12] = Util.ReplaceNullTo(info.CreatedDate, DBNull.Value);
                values[13] = Util.ReplaceNullTo(info.Type, DBNull.Value);
                values[14] = Util.ReplaceNullTo(info.Status, DBNull.Value);

                return _data.Update(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Delete(long teamID)
        {
            _error = "";
            try
            {
                object[] values = { teamID };
                return _data.Delete(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Delete(TeamInfo info)
        {
            _error = "";
            try
            {
                object[] values = { info.TeamID };
                return _data.Delete(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static TeamInfo Select(long teamID)
        {
            _error = "";
            try
            {
                object[] values = { teamID };
                DataTable dTable = _data.Select(values);
                if (dTable.Rows.Count < 1) return null;


                TeamInfo info = new TeamInfo(dTable.Rows[0]);
                return info;
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        public static DataTable SelectAll()
        {
            _error = "";
            try
            {
                return _data.SelectAll();
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        #endregion

    }
}